<?php
namespace App\Module\User\Service;

use App\Amqp\Producer\ActivityShareProducer;
use App\Amqp\Producer\MiniShareProducer;
use App\Amqp\Producer\SignProducer;
use App\Constants\Constant;
use App\Exception\AppException;
use Carbon\Carbon;
use Hyperf\Amqp\Producer;
use Hyperf\Di\Annotation\Inject;
use Qbhy\HyperfAuth\AuthManager;

class TaskService {

    /**
     * @Inject()
     * @var AuthManager $authManager
     */
    private $authManager;

    /**
     * @Inject()
     * @var ScoreService $scoreService
     */
    private $scoreService;

    /**
     * @Inject()
     * @var Producer $producer
     */
    private $producer;

    public function sign(){
        if($this->scoreService->getByCondition(Constant::DIRECTION_INC,Constant::SCORE_ORIGIN_SIGN,Carbon::now()->toDateString())){
            throw new AppException("请不要重复签到");
        }

        return $this->producer->produce(new SignProducer(['user_id'=>$this->authManager->guard(Constant::USER)->user()->getId()]));
    }

    public function miniShare($id){
        return $this->producer->produce(new MiniShareProducer(['user_id'=>$id,'source_id'=>$this->authManager->guard(Constant::USER)->user()->getId()]));
    }

    public function activityShare($sid,$aid){
        return $this->producer->produce(new ActivityShareProducer(['user_id'=>$sid,'source_id'=>$this->authManager->guard(Constant::USER)->user()->getId(),'act_id'=>$aid]));
    }
}